﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SunyuCRM.API.Weixin.CommonService.Common
{
    public class AutoReply
    {
        public string key { get; set; }
        public string text { get; set; }
    }

    public class AutoReplyUtils
    {
        private static List<AutoReply> autoReplyList;
        public static List<AutoReply> Instance
        {
            get
            {
                if (autoReplyList == null)
                {
                    autoReplyList = new List<AutoReply>();
                    try
                    {
                        StreamReader rsf = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + "\\App_Data\\autoreply.dat");
                        string strConfig = "";
                        while (rsf.Peek() >= 0)
                        {
                            strConfig += rsf.ReadLine();
                        }
                        rsf.Close();
                        autoReplyList = JsonHelper.DeserializeObject<List<AutoReply>>(strConfig);
                    }
                    catch (IOException e)
                    {
                        Console.WriteLine(e.ToString());
                    }
                }
                return autoReplyList;
            }
        }
    }
}